package svc

import (
	"UserServer/rpc/internal/config"
	"context"
	"github.com/redis/go-redis/v9"
	"go.uber.org/zap"
)

func InitRedis(redisCfg config.Redis, Log *zap.Logger) *redis.Client {
	//MaxIdleTime, _ := utils.ParseDuration(redisCfg.IdleTimeout)

	Rdb := redis.NewClient(&redis.Options{
		Addr:         redisCfg.Address,
		Password:     redisCfg.Password,
		DB:           redisCfg.DB,
		PoolSize:     redisCfg.PoolSize,
		MinIdleConns: redisCfg.MinIdleConn,
		//ConnMaxIdleTime: MaxIdleTime,
	})

	if _, err := Rdb.Ping(context.Background()).Result(); err != nil {
		Log.Error("Pooled redis ping failed:", zap.Error(err))
	}

	return Rdb
}
